﻿/// <reference path="RequestHandler.js" />
/// <reference path="../HttpRequest.js" />
/// <reference path="../../enhancements/auto-complete/AutoCompleteController.js" />
/// <reference path="../../enhancements/QuickPM.js" />
/// <reference path="../../enhancements/TextAreaController.js" />
///--------------------------------------------------------------------
/// <file name="CatchAllHandler.js">
///   Adds functionality to all pages.
/// </file>
///--------------------------------------------------------------------

NAMFox.ns(function() { with (NAMFox) {

this.CatchAllHandler = function() {
    this.priority = 0;
};

CatchAllHandler.prototype = new RequestHandler();
CatchAllHandler.prototype.name = "CatchAllHandler";

CatchAllHandler.prototype.handleRequestCore = function(request, _$) {
    /// <summary>Handles a request.</summary>
    /// <param name="request" type="HttpRequest">
    ///   The HTTP request which encapsulates the
    ///   document and route data for this request.
    /// </param>
    
    if (!request.htmlDocument.location.href.match(/\/w\/index\.php/)) {
        var autoComplete = request.htmlDocument.__namfox__.autoComplete =
            new AutoCompleteController(request.htmlDocument);
        
        autoComplete.attach();
    }
    
    var textAreaController = request.htmlDocument.__namfox__.textAreaController =
        new TextAreaController(request.htmlDocument);
    textAreaController.attach();

    var quickPM = new QuickPM(_$, request.htmlDocument);
    quickPM.attach();
};

}});